﻿using System;
using System.Collections.Generic;
using Assets.Scripts.GtsScripts;
using UnityEngine;

// Token: 0x020001D4 RID: 468
public class ActionController : MonoBehaviour
{
	// Token: 0x06000A06 RID: 2566 RVA: 0x0005980C File Offset: 0x00057A0C
	public void ScheduleAction(AgentAction action)
	{
		action.agent = this.agent;
		if (this.agent.isGiantess)
		{
			Giantess component = this.agent.GetComponent<Giantess>();
			component.GtsMovement.doNotMoveGts = false;
		}
		if (action.priority)
		{
			this.queue.AddFirst(action);
		}
		else
		{
			this.queue.AddLast(action);
		}
	}

	// Token: 0x06000A07 RID: 2567 RVA: 0x00059878 File Offset: 0x00057A78
	public void Execute()
	{
		if (this.queue.Count != 0)
		{
			AgentAction value = this.queue.First.Value;
			bool flag = true;
			foreach (AgentAction agentAction in this.active)
			{
				flag &= (agentAction.CanDoBoth(value) || value.CanDoBoth(agentAction));
			}
			if (flag)
			{
				this.queue.RemoveFirst();
				this.active.Add(value);
			}
		}
		for (int i = 0; i < this.active.Count; i++)
		{
			if (this.active[i].IsCompleted())
			{
				EventManager.SendEvent(new ActionCompleteEvent(this.agent, this.active[i]));
				this.active.RemoveAt(i--);
			}
		}
		this.active.ForEach(delegate(AgentAction action)
		{
			action.Execute();
		});
	}

	// Token: 0x06000A08 RID: 2568 RVA: 0x000599B4 File Offset: 0x00057BB4
	public void FixedExecute()
	{
		for (int i = 0; i < this.active.Count; i++)
		{
			if (this.active[i].IsCompleted())
			{
				EventManager.SendEvent(new ActionCompleteEvent(this.agent, this.active[i]));
				this.active.RemoveAt(i--);
			}
		}
		this.active.ForEach(delegate(AgentAction action)
		{
			action.FixedExecute();
		});
	}

	// Token: 0x06000A09 RID: 2569 RVA: 0x00059A47 File Offset: 0x00057C47
	private void Awake()
	{
		this.queue = new LinkedList<AgentAction>();
		this.agent = base.GetComponent<Humanoid>();
		this.agent.animationManager = base.gameObject.AddComponent<AnimationManager>();
	}

	// Token: 0x06000A0A RID: 2570 RVA: 0x00059A76 File Offset: 0x00057C76
	public void SetAgent(Humanoid agent)
	{
		this.agent = agent;
	}

	// Token: 0x06000A0B RID: 2571 RVA: 0x00059A7F File Offset: 0x00057C7F
	public void ClearQueue()
	{
		this.queue.Clear();
	}

	// Token: 0x06000A0C RID: 2572 RVA: 0x00059A8C File Offset: 0x00057C8C
	public void ClearAll()
	{
		this.ClearQueue();
		this.active.ForEach(delegate(AgentAction action)
		{
			action.Interrupt();
		});
		this.active.Clear();
	}

	// Token: 0x06000A0D RID: 2573 RVA: 0x00059AC7 File Offset: 0x00057CC7
	public bool IsIdle()
	{
		return this.queue.Count == 0 && this.active.Count == 0;
	}

	// Token: 0x06000A0E RID: 2574 RVA: 0x00059AEA File Offset: 0x00057CEA
	public bool IsQueueEmpty()
	{
		return this.queue.Count == 0;
	}

	// Token: 0x04000F7A RID: 3962
	private List<AgentAction> active = new List<AgentAction>();

	// Token: 0x04000F7B RID: 3963
	private LinkedList<AgentAction> queue;

	// Token: 0x04000F7C RID: 3964
	private Humanoid agent;
}
